<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
</head>
<body>
<!--<script src="lib/PromiseNew.js"></script>-->
<script src="lib/PromiseClass.js"></script>
<!--<script>-->
<!--    const p = new Promise((resolve,reject)=>{-->
<!--        setTimeout(()=>{-->
<!--            // resolve(1)-->
<!--            reject(2)-->
<!--            console.log('reject()改变状态之后')-->
<!--        })-->
<!--    })-->
<!--    p.then(-->
<!--        value => {-->
<!--            console.log('onResolved1',value)-->
<!--        },-->
<!--        reason => {-->
<!--            console.log('onRejected1',reason)-->
<!--        }-->
<!--    )-->
<!--    p.then(-->
<!--        value => {-->
<!--            console.log('onResolved2',value)-->
<!--        },-->
<!--        reason => {-->
<!--            console.log('onRejected2',reason)-->
<!--        }-->
<!--    )-->
<!--</script>-->

<!--<script>-->
<!--    new Promise((resolve,reject)=>{-->
<!--        setTimeout(()=>{-->
<!--            // resolve(1)-->
<!--            reject(2)-->
<!--        })-->
<!--    }).then(-->
<!--        value => {-->
<!--            console.log('onResolved1',value)-->
<!--        },-->
<!--        reason => {-->
<!--            console.log('onRejected1',reason)-->
<!--            // return 3-->
<!--            // throw 4-->
<!--            return new Promise((resolve, reject) => {-->
<!--                reject(5)-->
<!--            })-->
<!--        }-->
<!--    ).then(-->
<!--        value => {-->
<!--            console.log('onResolved2',value)-->
<!--        },-->
<!--        reason => {-->
<!--            console.log('onRejected2',reason)-->
<!--            throw 6-->
<!--        }-->
<!--    ).catch(reason => {-->
<!--        console.log('onRejected3',reason)-->
<!--        return new Promise(()=>{}) //中断promise链-->
<!--    }).then(-->
<!--        value => {-->
<!--            console.log('onResolved4',value)-->
<!--        },-->
<!--        reason => {-->
<!--            console.log('onRejected4',reason)-->
<!--            throw 6-->
<!--        }-->
<!--    )-->
<!--</script>-->

<script>
    // const p4 = new Promise((resolve)=>{
    //     setTimeout(()=>{
    //         resolve(5)
    //     },1000)
    // })
    const p4=Promise.resolveDelay(5,1000)
    const p5 = Promise.reject(6)
    const p1=Promise.resolve(2) // 如果是一般值，p1成功，value就是这个值
    const p2=Promise.resolve(Promise.resolve(3)) // 如果是成功的promise，p2成功，value就是这个promise的value
    const p3=Promise.resolve(Promise.reject(4)) // 如果是失败的promise p3失败 reason就是这个promise的reason
    p1.then(value => {console.log('p1',value)})
    p2.then(value => {console.log('p1',value)})
    p3.catch(reason => {console.log('p1',reason)})

    const pAll=Promise.all([p4,8,p1,p2])
    pAll.then(
        value => {
            console.log('all onResolved',value)
        },
        reason => {
            console.log('all onRejected',reason)
        }
    )

    const pRace=Promise.race([p5,7,p1,p2])
    pRace.then(
        value => {
            console.log('race onResolved',value)
        },
        reason => {
            console.log('race onRejected',reason)
        }
    )

    const p6=Promise.resolveDelay(66,2000)
    const p7=Promise.rejectDelay(77,3000)
    p6.then(
        value=>{
            console.log('p6',value)
        }
    )
    p7.catch(
        reason=>{
            console.log('p7',reason)
        }
    )
</script>
</body>
</html>
